<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>新增bug</title>
	<base href="<%=basePath%>"/>
	<link rel="stylesheet" type="text/css" href="css/common.css" />
	<link rel="stylesheet" href="<%=basePath%>/js/uploadify/css/uploadify.css" type="text/css"></link>
    <link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
    <script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
    <script type="text/javascript" src="<%=basePath%>/js/uploadify/jquery.uploadify-3.1.min.js"></script>
	<style type="text/css"> 
	  fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
	  form label {font-weight:bold;}
	  table{margin:10px 10px};
	  td{line-height: 40px;}
	  input[type="text"]{width:250px;}
	  input[type="password"]{width:250px;}
	  input[type="textarea"]{width:250px;}
	</style>

	<script type="text/javascript">
	  var bugId = null;  
	  $(document).ready(function(){
		     
		     $('#enname').focus();
		     
		     $.ajaxSetup ({ cache:false,async: false });
		     $("#moduleId").mcDropdown("#categorymenu",{ dropShadow: false, targetColumnSize: 1, lineHeight:30, allowParentSelect:true});
		     
		     //异步提交表单
		     var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
		     $("#bugForm").submit(function(){
		         $(this).ajaxSubmit(options);
		          return false;
		     });   
		   
	         //文件上传组件
		     $("#file_upload").uploadify({   
                  'height'        : 27,    
    	          'width'         : 80,     
    	          'buttonText'    : '添加附件', 
    	          
    	          'removeCompleted': false,         //上传完毕上传列表是否去除 
    	          'fileSizeLimit': '50MB',          //上传文件大小设置 单位可以是B、KB、MB、GB 
                  'swf'           : 'js/uploadify/uploadify.swf',   
    	          'uploader'      : 'soft/bug/upload.do',   
    	          'auto'          : false,   
    	          'formData'      : {'bugId':''},  
    	          'fileTypeExts'  : '*.*',   
    	          'onUploadStart' : function(file) {   
    	                $("#file_upload").uploadify("settings","formData", {'bugId':bugId});   
    	           },   
    	          'onUploadSuccess':function(file, data, response){ 
		        	  $('#' + file.id).find('.data').html(' 上传完毕');
    	           },   
    	          'onUploadComplete':function(file){   
    	             
    	           }   
		      });
	   });
	 
	   //提交前验证
	   function beforeSubmit() {
		     if(isEmpty($("#title").val())) { alert("摘要不能为空！"); return false; }
		     if(isEmpty($("#moduleId").val())) { alert("所属模块不能为空！"); return false; }
		     if(isEmpty($("#expurgator").val())) { alert("修订人不能为空！"); return false; }
		     if(isEmpty($("#description").val())) { alert("描述不能为空！"); return false; }

		     return true;
	   }
	
	   function process(responseJson) {
	     if(responseJson.code == 0) {
	         $('#error_label').text("错误信息：" + responseJson.message);
	         $("#p_error").show();
	         return;
	     }
	     else
	     {   
	    	 $("#bugId").val(responseJson.bugId);
	    	 if(confirm('添加成功是否上传附件?'))
          	 {  
	    		 $("#btn_insert").attr('disabled','true');
          	 }else
          	 {
          		 var qs = $("#qs").val();
         	     location.href = "<%=basePath%>soft/bug/list.do?" + qs;
          	 }
	     }
	   }  
	   
	   function startUpload(){   
		  bugId = $("#bugId").val();
		  if(bugId.replace(/\s/g,'') == '')
		  {
			  alert("bug不能为空！");   
              return false;    
		  }else
	      {
			  $('#file_upload').uploadify('upload','*');   
	      }
	   }   

	   //返回列表页面
	   function btn_return(){
		    var qs = $("#qs").val();
	    	window.location.href="<%=basePath%>soft/bug/list.do?" + qs;
	   }
	</script>
</head>
<body>
  <div>
    <fieldset>
      <legend>新增bug：</legend>
      <form id="bugForm" method="post" action="soft/bug/insert.do">
        <input id="qs" name="qs" type="hidden" value="${qs}"/>
      	<p id = "p_error" style = "margin:10px 10px;">
      	    <label id="error_label" style="color:red;"></label>
      	</p>
        <table>
            <tr>
			    <td><label for="project">所属项目：</label>
			         <input type="hidden" name="bugId" id="bugId">
			         <input type="hidden" name="projectId" value="${project.id}">
			    </td>
			    <td><input type="text"  value="${project.name}" disabled="disabled" /><font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
		    </tr>
            <tr>
				<td><label for="title">摘要：</label></td>
				<td><input type="text" name="title" id="title" value="${bug.title}" />
				<font color="red">&nbsp;*&nbsp;&nbsp;</font>
				</td>
			</tr>
			<tr>
				<td><label for="moduleId">模块：</label></td>
				<td>
				   <c:if test="${!empty treeList}">
	               <input name="moduleId" id="moduleId" id="pNo"/>
	                <ul id="categorymenu" class="mcdropdown_menu">
				        <c:forEach items="${treeList}" var="tree" varStatus="status">
				            ${tree}
				        </c:forEach>
			        </ul>  	
		           </c:if>  	
			       <c:if test="${empty treeList}">
		               <input type="text" disabled="disabled" value="请先为此项目添加模块" style="width:200px;">
			       </c:if>  	
				</td>
			</tr>
			<tr>
			    <td><label for="expurgator">修订人：</label></td>
				<td>
				   <select name="expurgator" id="expurgator" style="width:153px;" >
				     <c:forEach items="${userList}" var="u" >
				            <option value="${u.enname}"><c:out value="${u.cnname}"/></option>
				     </c:forEach>
					</select>
				</td>
			</tr>
			<tr>
					<td><label for="bugLevel">级别：</label></td>
					<td>
					    <select name="bugLevel" id="bugLevel" style="width:153px;">
							<c:forEach items="${bugLevelList}" var="bl">
						      <option value="${bl.value}"> ${bl.name}</option>
						  	</c:forEach>
					    </select>
					<font color="red">&nbsp;*&nbsp;&nbsp;</font>
					</td>
				</tr>
			<tr>
				<td><label for="status">状态：</label></td>
				<td>
				     <select name="status" id="status" style="width:153px;" >
			              <c:forEach items="${bugStatusList}" var="bs">
			                 <c:if test="${bs.value == 'new'}">
			                   <option value="${bs.value}">   ${bs.name}</option>
			                 </c:if>
						  </c:forEach>
					 </select>
				</td>
			</tr>
			<tr>
				<td valign="top"><label for="description">Bug描述：</label></td>
				<td valign="top"><textarea name="description" id="description" cols="40" rows="8"></textarea> <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
			</tr>
			<tr>
				<td></td>
				<td>
				    <input type="submit" id="btn_insert" value="提交" style="width: 80px;" />
				    <input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width: 80px;" />
				</td>
			</tr>
        </table>
      </form>
    </fieldset>
    </div>
   	<div id="uploadDiv" >
		<fieldset>
		   <legend>上传附件：</legend>
		   <input type="file" name="uploadify" id="file_upload" />   
		   <hr>   
           <a onclick="startUpload();" href="javascript:void(0);">开始上传</a>    
           <a href="javascript:$('#file_upload').uploadify('cancel', '*')" >取消所有上传</a>   
        </fieldset>
    </div>
</body>
</html>